<?php
class fields extends spController
{
		function admin_fields()
		{
			$m_fields = spClass('m_fields');
			$this->type = $_GET['type'] ? $_GET['type'] :'activity_' . $_GET['acid'];
			$this->field_result = $m_fields->findAll(array('type'=>$this->type));
			$this->display('admin/fields_list.html');
		}

		function add_fields()
		{
			$m_fields = spClass('m_fields');
			if(!empty($_POST)) {
				$array_fields['field_name'] = $_POST['field_name'];
				$array_fields['field_type'] = $_POST['field_type'];
				$array_fields['settings'] = $_POST['settings'];
				$array_fields['type'] = $_POST['type'];
				$m_fields->create($array_fields);
				$this->success('提交成功', spUrl('fields', 'admin_fields'));
			} else {
				$this->type = $type = $_GET['type'] ? $_GET['type'] :'activity_' . $_GET['acid'];
				$this->display('admin/fields_add.html');
			}
		}

		function edit_fields()
		{
			$m_fields = spClass('m_fields');
			if(!empty($_POST)) {
				$field_id = intval($_POST['field_id']);
				$array_fields['field_name'] = $_POST['field_name'];
				$array_fields['field_type'] = $_POST['field_type'];
				$array_fields['settings'] = addslashes($_POST['settings']);
				$m_fields->update(array('field_id'=>$field_id), $array_fields);
				$this->success('提交成功', spUrl('fields', 'admin_fields', array('type'=>$_POST['type'])));
			} else {
				$field_id = intval($_GET['field_id']);
				$this->result = $m_fields->find(array('field_id'=>$field_id));
				$this->display('admin/fields_edit.html');
			}
		}
}
?>